<?php
 include('../../Connections/KRAPPERCON.php');
 $cini = $_POST['t_ro_cini'];
 $cfin = $_POST['t_ro_cfin'];
 $dini = $_POST['t_ro_dini'];
 $dfin = $_POST['t_ro_dfin'];
  $eini = $_POST['t_ro_eini'];
 $efin = $_POST['t_ro_efin'];
 $usr  = $_POST['t_ro_usr'];;
 $sdet1 = '';
 $sdet2 = '';
 $f_det = getVal('filter_det');
 $cart = getVal('tspc_cart');
 $aalm = getVal('cbo_alm');
 $asts = getVal('sp_sts');
 
// $alm = '';
 $pro = $_POST['cbo_ro_pro'];;
//$cen = $_POST['cbo_ro_cen'];

$str_usr = '';
$tsr_cini= '';
$str_cfin = '';
$str_dini = '';
$str_dfin = '';
$str_efin = '';
$str_eini = '';
$str_art = '';
$str_alm = '';
$str_sts = '';
$sdet3 = 'OrdenMonto';
if ( $f_det == '1'){
$sdet3 = 'DetPreNet';
$sdet1 = ',po.ArticuloID,po.AlmacenID,po.CtdUM,po.PreUM,po.CtdCons,po.UniMed';
$sdet2 =' inner join tt_detsolped po on po.SolPedID = sp.SolPedID ';
// Agregar FIltros a nivel de Detalle
$str_art = isNull($cart," and po.ArticuloID = '".$cart."'");
$str_alm = isNull($aalm," and po.AlmacenID = '".$aalm."'");
	if ($asts == '1') {
	$str_sts = " and po.DetOrdQtp > po.DetOrdQta";
	}
	else if($asts == '2'){
	$str_sts = " and po.DetOrdQtp = po.DetOrdQta";
	}
}

$str_pro = isZeros($pro,"and pr.ProveedID=$pro");
//$str_alm = isZeros($alm,"and 
$str_usr = isNull($usr,"and sp.UserID='".$usr."'");

if (!isEmpty($cfin)){
$str_cini = isNull($cini," and date(sp.SolPedFeC) >= '".$cini."'");
$str_cfin = isNull($cfin," and date(sp.SolPedFeC) <= '".$cfin."'");
}
else {
$str_cini = isNull($cini," and date(sp.SolPedFeC) = '".$cini."'");
}

if (!isEmpty($dfin)){
$str_dini = isNull($dini," and sp.SolPedFeD >= '".$dini."'");
$str_dfin = isNull($dfin," and sp.SolPedFeD <= '".$dfin."'");
}
else {
$str_dini = isNull($dini," and sp.SolPedFeD = '".$dini."'");
}

if (!isEmpty($dfin)){
$str_eini = isNull($eini," and sp.SolPedFeE >= '".$eini."'");
$str_efin = isNull($efin," and sp.SolPedFeE <= '".$efin."'");
}
else {
$str_eini = isNull($eini," and sp.SolPedFeE = '".$eini."'");
}

$str_cen = '';
//$str_cen = isZeros($cen," oc.CentroID = ".$cen);
$where = '';
$cond = ($str_pro." "." ".$str_art." ".$str_alm." ".$str_cen." ".$str_usr." ".$str_cini. "  ".$str_cfin." " .$str_dini. " " . $str_dfin."  ".$str_eini."  ".$str_efin." ".$str_sts);
if (!trim($cond)=='' ){
$cond = ltrim($cond);
$where = "where ".substr($cond,3);
}



 
 $sql = "SELECT
sp.SolPedID,
sp.SolPedFeD,
sp.UserID,
sp.ProveedorID,
pr.ProveedNom,
sp.SolPedFeC,
sp.SolPedFeE,
sp.MoneyID,
sp.ClaDocID " . $sdet1 ."
FROM tt_solped as sp inner join tt_proveedor AS pr 
on sp.proveedorID = pr.proveedID ".$sdet2 .$where." order by sp.SolPedID ";
 doEcho($sql); 
?>
<table width="100%" rules="all" border="1" cellspacing="0" cellpadding="0">
<thead>
  <tr>
    <th>Nro de Orden</th>
    <th>F.Creacion</th>
        <th>F.Documento</th>
        <th>Fecha Entrega</th>
    <th>Proveedor</th>
    <th>Creador</th>
    <?php if ($f_det == '1') { ?>
    <th>Articulo</th>
        <th>Almacen</th>
         <th>Ctd.Ped.</th>
          <th>UM</th>
          <th>Ctd.Pend.</th>          
	      <th>PreUM</th>
          <th>Bruto</th>
      <?php 
	}
	?>
<!--    <th>Liberacion</th> -->
  </tr>
  </thead>
  <tbody>
  <?php 

//$sql = 'call sp_getAll_OC();';
$res = $mysqli->query($sql);

$tot = 0;
if ($res){
while( $row = $res->fetch_assoc()){
//$tot += $row['OrdenMonto'];
  ?>
  <tr>
    <td><a href="#" onclick="viewSP(this)"><?php echo $row['SolPedID'];?></a></td>
    <td><?php echo $row['SolPedFeC'];?></td>
	    <td><?php echo $row['SolPedFeD'];?></td>
        <td><?php echo $row['SolPedFeE'];?></td>
    <td><?php echo $row['ProveedorID']."/".$row['ProveedNom'];?></td>
    <td><?php echo $row['UserID']?></td>
     <?php if ($f_det == '1') {
	 $qpend = $row['CtdUM']-$row['CtdCons'];
	 $bru = $row['PreUM'] * $qpend;
	  ?>
    <td><?php echo $row['ArticuloID']?></td>
        <td><?php echo $row['AlmacenID']?></td>
         <td class="qt"><?php echo $row['CtdUM']?></td>
          <td class="qt"><?php  echo $row['UniMed'];?></td>
          <td class="qt"><?php echo $qpend;?></td>
	      <td class="qt"><?php echo $row['PreUM']?></td>
          <td class="qt"><?php echo $bru;?></td>
      <?php 
	}
	?>
    <!-- <td><?php if ($row['OrdenLibre']==1) echo 'No'; else 'Si'; ?></td> -->
  </tr>
  <?php 
  }
  $res->close();
  
  $mysqli->check_result(); 
  }
  ?>
  </tbody>
  <tfoot>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>  
      <?php if ($f_det == '1') { ?>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td> 
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<?php 
	}
	?>
  </tr>
  </tfoot>
</table>
<?php 

?>